<template>
	<view class="items" style="height: 100%;overflow: auto;">
		<view class="item">
			<view class="top" v-if="info.userInfo">
				<u-avatar :src="info.userInfo.avatar"></u-avatar>
				<view class="" style="flex: 1;margin-left: 20rpx;">
					<view class="" v-if="info.userInfo" style="display: flex;align-items: center;">
						{{info.userInfo.username || '--'}}
						<view class=""
							style="color: #2DBC26;font-size: 24rpx;margin-left: 10rpx;font-weight: 400;text-align: right;">
							{{parseFloat((Number(js1.distance) / 1000).toFixed(2))}} km
						</view>
					</view>
					<view class="" style="color: #7B7878;font-size: 24rpx;">
						{{formatTimestamp(info.createtime)}}
					</view>
				</view>
				<view class="" style="color: #FB1E1B;font-size:34rpx;font-weight: 600;">
					￥100
				</view>
			</view>
			<view class="" style="margin: 10rpx 0;">
				{{info.title}}
			</view>
			<view class="imgs" >
				<image :src="img" mode="" v-for="(img,ind) in info.images" :key="ind"></image>
			</view>
			<view class=""
				style="display: flex;align-items: center;justify-content: space-between;margin-top: 20rpx;color: #656565;">
				<view class="" style="display: flex;align-items: center;">
					<u-icon name="eye" color="#656565" size="22"></u-icon>
					<text style="margin-left: 6rpx;">浏览 {{info.view+1}}</text>
				</view>
				<view class="">
					收藏 {{info.collect}}
				</view>
			</view>
		</view>
		<view class="item1">
			<view class="tip">
				<view class="bor">
				</view>
				<view class="">
					视频
				</view>
			</view>
			<view class="" style="margin-bottom: 20rpx;">
				<video :src="info.video"></video>
			</view>
			<view class="" style="display: flex;flex-wrap: wrap;">
				<view class="" style="width: 50%;">
					<view class="tip">
						<view class="bor">
						</view>
						<view class="">
							体重
						</view>
					</view>
					<view class="" style="margin-bottom: 20rpx;">
						{{info.weigh}} kg
					</view>
				</view>
				<view class="" style="width: 50%;">
					<view class="tip">
						<view class="bor">
						</view>
						<view class="">
							身高
						</view>
					</view>
					<view class="" style="margin-bottom: 20rpx;">
						{{info.high}} m
					</view>
				</view>
				<view class="" style="width: 50%;">
					<view class="tip">
						<view class="bor">
						</view>
						<view class="">
							年龄
						</view>
					</view>
					<view class="" style="margin-bottom: 20rpx;">
						{{info.age}}
					</view>
				</view>
				<view class="" style="width: 50%;">
					<view class="tip">
						<view class="bor">
						</view>
						<view class="">
							品种
						</view>
					</view>
					<view class="" style="margin-bottom: 20rpx;">
						{{info.brand}}
					</view>
				</view>
			</view>
			<view class="tip">
				<view class="bor">
				</view>
				<view class="">
					地址
				</view>
			</view>
			<view class="" style="margin-bottom: 20rpx;">
				{{info.address}}
			</view>

		</view>
		<view class="" style="height: 140rpx;color: rgba(1, 1, 1, 0);">
			1
		</view>
		<view class="footer">
			<view class="" style="display: flex;color: #646464;">
				<view class="" style="display: flex;flex-direction: column;align-items: center;margin-right: 40rpx;"
					@click="collect">
					<u-icon name="star-fill" color="#f8fa49" size="26" v-if="info.isCollect"></u-icon>
					<u-icon name="star" color="#646464" size="26" v-if="!info.isCollect"></u-icon>
					<text style="margin-top: 6rpx;color: #646464;" v-if="info.isCollect">收藏</text>
					<text style="margin-top: 6rpx;color: #646464;" v-if="!info.isCollect">收藏</text>
				</view>
				<view class="" style="display: flex;flex-direction: column;align-items: center;margin-right: 20rpx;"
					@click="callPhoneNumber">
					<u-icon name="phone" color="#646464" size="26"></u-icon>
					<text style="margin-top: 6rpx;color: #646464;">电话</text>
				</view>
			</view>
			<view class="btn" @click="toChat">
				聊一聊
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getInfo,
		addCollectInfo
	} from "@/request/api/tiezi.js"
	export default {
		data() {
			return {
				info: {},
				js1: {}
			}
		},
		onLoad(opt) {
			let js1 = JSON.parse(opt.item);
			this.js1 = js1;
			getInfo({
				id: js1.id
			}).then(res => {
				res.data.images = res.data.images.split(',');
				this.info = res.data;
			})
		},
		methods: {

			collect() {
				addCollectInfo({
					info_id: this.info.id
				}).then(res => {
					this.info.isCollect = !this.info.isCollect;
					if (this.info.isCollect) {
						this.info.collect += 1
					} else {
						this.info.collect -= 1
					}
				})
			},
			toChat() {
				uni.navigateTo({
					url: "/pages/chat/chat"
				})
			},
			callPhoneNumber() {
				uni.makePhoneCall({
					phoneNumber: this.info.userInfo.mobile, // 仅为示例，请传正确的电话号码
					success: () => {}
				});
			},
			formatTimestamp(timestamp) {
				// 创建 Date 对象
				const date = new Date(timestamp * 1000); // 将时间戳转换为毫秒

				// 获取年份、月份、日期、小时、分钟、秒
				const year = date.getFullYear();
				const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始，需要加1
				const day = String(date.getDate()).padStart(2, '0');
				const hour = String(date.getHours()).padStart(2, '0');
				const minute = String(date.getMinutes()).padStart(2, '0');
				const second = String(date.getSeconds()).padStart(2, '0');

				// 返回格式化的日期时间字符串
				return `${year}-${month}-${day}`;
			},
		}
	}
</script>
<style>
	page {
		height: 100%;
		overflow: auto;
	}
</style>
<style scoped lang="scss">
	.footer {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100vw;
		max-width: 100vw;
		display: flex;
		align-items: center;
		padding: 20rpx 30rpx;
		background-color: white;
		justify-content: space-between;
		box-sizing: border-box;

		.btn {
			background-color: #2DBC26;
			color: white;
			padding: 16rpx 30rpx;
			border-radius: 100px;
			font-size: 26rpx;
		}
	}

	.item1 {
		border-radius: 20rpx;
		background-color: white;
		padding: 30rpx;
		margin-bottom: 20rpx;

		.tip {
			display: flex;
			align-items: center;
			margin-bottom: 6rpx;

			.bor {
				background-color: #2DBC26;
				width: 8rpx;
				height: 28rpx;
				border-radius: 0 20rpx 20rpx 0;
				margin-right: 14rpx;
			}
		}
	}

	.items {
		border-radius: 20rpx;
		padding: 30rpx;

		.item {
			border-radius: 20rpx;
			background-color: white;
			padding: 30rpx;
			margin-bottom: 20rpx;

			.top {
				display: flex;
				align-items: center;

				image {
					width: 80rpx;
					height: 80rpx;
					border-radius: 100px;
					margin-right: 20rpx;
				}

				.more {
					width: 40rpx;
					height: 10rpx;
					margin-right: 0;
				}
			}

			.imgs {
				display: flex;
				justify-content: space-between;
				flex-wrap: wrap;
				image {
					width: 190rpx;
					height: 190rpx;
					border-radius: 30rpx;
					margin-bottom: 10rpx;
				}
			}
		}
	}
</style>